{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">

    <blockquote class="layui-elem-quote layui-text">
        温馨提醒：右上角可放大全屏编辑；
    </blockquote>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>{$info['table_title']|default='数据列表信息'}</legend>
    </fieldset>

    <div class="layui-form">
        <input type="hidden" name="role_id" value="{$role_id|default=0}">
        <table class="layui-table" lay-even="" lay-skin="row">
            <colgroup>
                <col width="400">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>主菜单权限</th>
                <th>操作权限</th>
                <!--<th>读写权限</th>-->
                <!--<th>删除权限</th>-->
            </tr>
            </thead>
            <tbody>
            {foreach $menuList as $menuInfo}
            <tr class="tr">
                <td>
                    <div class="layui-form-item" pane="">
                        <div class="layui-input-block">
                            <input type="checkbox" class="parent_menu" lay-filter="parent_menu" value="{$menuInfo.id}" name="menu_id[{$menuInfo.id}]" lay-skin="primary" title="{$menuInfo.menu_name}" {if $menuInfo.is_checked}checked=""{/if}>
                        </div>
                    </div>
                </td>
                </td>
                <td class="td">
                    <div class="layui-form-item" pane="">
                        <div class="layui-input-block">
                            {foreach $menuInfo['child'] as $childMenuInfo}

                            <input type="checkbox" class="child_menu" lay-filter="child_menu" value="{$childMenuInfo.id}" name="menu_id[{$childMenuInfo.id}]" lay-skin="primary" title="{$childMenuInfo.menu_name}" {if !empty($childMenuInfo.is_menu)}checked=""{/if} >

                            {/foreach}
                        </div>
                    </div>
                </td>
                <!--<td class="td">-->
                    <!--<div class="layui-form-item" pane="">-->
                        <!--<div class="layui-input-block">-->
                            <!--{foreach $menuInfo['child'] as $childMenuInfo}-->
                            <!--<input type="checkbox" class="child_menu" lay-filter="child_menu" value="{$childMenuInfo.menu_id}" name="menu_id[{$childMenuInfo.menu_id}]" lay-skin="primary" title="{$childMenuInfo.menu_name}" {if !empty($childMenuInfo.rm_role)}checked=""{/if} >-->
                            <!--{/foreach}-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</td>-->
                <!--<td class="td">-->
                    <!--<div class="layui-form-item" pane="">-->
                        <!--<div class="layui-input-block">-->
                            <!--{foreach $menuInfo['child'] as $childMenuInfo}-->
                            <!--<input type="checkbox" class="child_menu" lay-filter="child_menu" value="{$childMenuInfo.menu_id}" name="menu_id[{$childMenuInfo.menu_id}]" lay-skin="primary" title="{$childMenuInfo.menu_name}" {if !empty($childMenuInfo.rm_role)}checked=""{/if} >-->
                            <!--{/foreach}-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</td>-->
            </tr>
            {/foreach}
            </tbody>
        </table>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary" id="closeIframe">关闭</button>
            </div>
        </div>
    </div>
</div>
{include file='common/footer'}
<script>

    layui.use(['form', 'layedit', 'laydate'], function(){

        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date'
        });
        //创建一个编辑器
        var editIndex = layedit.build('contentDome');

        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(is_mailSwitch)', function(data){
            this.checked ? $('.mail_number').show() :$('.mail_number').hide()
//            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });
        //监听指定开关
        form.on('switch(is_hotSwitch)', function(data){
//            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
//                offset: '6px'
//            });
//            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });
//        监听全选
        form.on('checkbox(parent_menu)', function(data){
            var checkbox=$(data.elem).parents('.tr').find('.child_menu');
            if(data.elem.checked){
                checkbox.attr('checked',true)
                checkbox.siblings('div').addClass('layui-form-checked');
            }else{
                checkbox.removeAttr('checked')
                checkbox.siblings('div').removeClass('layui-form-checked');
            }
        });
        form.on('checkbox(child_menu)', function(data){
            var checkbox=$(data.elem).parents('.td').find('.child_menu');
            var parent=$(data.elem).parents('.tr').find('.parent_menu');
            if(checkbox.siblings().hasClass('layui-form-checked')){
                parent.attr('checked',true)
                parent.siblings().addClass('layui-form-checked');
            }else{
                parent.removeAttr('checked')
                parent.siblings().removeClass('layui-form-checked');
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            $.ajax({
                url: '{:url("Role/ApiSaveRoleConfig")}',
                type: 'get',
                dataType: 'json',
                data: data.field,
                success: function (obj) {
                    if(obj.code==200){
                        parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index,data.field); //再执行关闭
                    }
                    if(obj.code==400){
                        parent.layer.msg(obj.msg, {icon: 5,time: 1000});
                    }
                },
                error:function(data){
                    console.log(data);
                }
            });
        });
        $('#closeIframe').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

    });


</script>

</body>
</html>